<?php
/**
 * Object Relational Persistence Mapping Class for table: package
 *
 * @package	com.athena
 * @author	LHV
 */
class Package extends ORDataObject {

	/**#@+
	 * Fields of table: package mapped to class members
	 */
	var $package_id		= '';
	var $vi_name		=	'';
	var $en_name		=	'';
	var $note			= '';
	/**#@-*/


	/**
	 * DB Table
	 */
	var $_table = 'package';

	/**
	 * Primary Key
	 */
	var $_key = 'package_id';
	
	/**
	 * Internal Name
	 */
	var $_internalName = 'Package';

	/**
	 * Handle instantiation
	 */
	function Package() {
		parent::ORDataObject();
	}

	public function listAll() {
		$ds = new Datasource_sql();
		$sql = array (
			'cols'	=> "package_id, name",
			'from'	=> $this->_table,
			'orderby'	=> "package_id");
		$ds->setup($this->_db, $sql);
		return $ds->toArray('package_id', 'name');
	}
	
	public function getPackageInfo() {
		$field		=	L10nHelper::getLocale();
		$field		=	L10nHelper::changeField($field, "name");
		$ds = new Datasource_sql();
		$sql = array (
			'cols'		=>	"package_id, $field name, note",
			'from'		=>	"$this->_table",
			'orderby'	=>	"name"
			);
		$ds->setup($this->_db, $sql);
		$ds->registerFilter('name', array(&$this, '_actionEditLink'));
		return $ds->toArray();
	}
	
	function _actionEditLink($value, $rowValues) {
		$id=$rowValues['package_id'];
		return "<a href=\"" . "javascript:loadPackagePage('pageContent', 'EditPackage', $id);" . "\">$value</a>";
	}
	
	public function delete($packageId) {
		$this->_execute("delete from $this->_table where package_id = $packageId");
	}
	
}
?>
